'use strict';

// 三种情况
// 1.一条记录
// 2.0条记录
// 3.多条记录

describe('highlight filter', function() {
  var $highlight;

  var article =
    'When I think of my wife, I always think of her head. The shape of it, to begin with. The very first time I saw her, it was the back of the head, and there was something lovely about it, the angles of it. Like a shiny, had corn kernel or a riverbed fossil. She had what the Victorians would call a finely shaped head. You could imagine the skull quite easily.'

  beforeEach(module('fbdApp.auxModule'));
  beforeEach(inject(function(_$filter_) {
    $highlight = _$filter_('highlightFilter');
  }));

  it('should be defined', function(done) {
    expect($highlight).toBeDefined();
    return done();
  });

  it('1 match', function(done) {
    var array = [{
      location: [5, 20],
      text: 'I think of my wife, '
    }];

    var expected =
      'When <span class="highlight">I think of my wife, </span>I always think of her head. The shape of it, to begin with. The very first time I saw her, it was the back of the head, and there was something lovely about it, the angles of it. Like a shiny, had corn kernel or a riverbed fossil. She had what the Victorians would call a finely shaped head. You could imagine the skull quite easily.'

    expect($highlight(array, article)).toBe(expected);
    return done();
  });

  it('0 match', function(done) {

    var array = [];

    var expected =
      'When I think of my wife, I always think of her head. The shape of it, to begin with. The very first time I saw her, it was the back of the head, and there was something lovely about it, the angles of it. Like a shiny, had corn kernel or a riverbed fossil. She had what the Victorians would call a finely shaped head. You could imagine the skull quite easily.'

    expect($highlight(array, article)).toBe(expected);
    return done();
  });

  it('more than 1 matches', function(done) {

    var array = [{
      location: [5, 2],
      text: 'I '
    }, {
      location: [10, 20],
      text: 'nk of my wife, I alw'
    }, {
      location: [31, 6],
      text: 'ys thi'
    }];

    var expected =
      'When <span class="highlight">I </span>thi<span class="highlight">nk of my wife, I alw</span>a<span class="highlight">ys thi</span>nk of her head. The shape of it, to begin with. The very first time I saw her, it was the back of the head, and there was something lovely about it, the angles of it. Like a shiny, had corn kernel or a riverbed fossil. She had what the Victorians would call a finely shaped head. You could imagine the skull quite easily.'

    expect($highlight(array, article)).toBe(expected);
    return done();
  });
})
